package com.cloud.drore.eboss.supplier.controller;

import com.cloud.drore.eboos.common.base.PagePo;
import com.cloud.drore.eboos.common.base.ResultMessage;
import com.cloud.drore.eboos.common.entity.supplier.ProductRelation;
import com.cloud.drore.eboos.common.entity.supplier.Ticket;
import com.cloud.drore.eboos.common.entity.supplier.po.CombinationProductQueryPo;
import com.cloud.drore.eboos.common.entity.supplier.po.TicketQueryPo;
import com.cloud.drore.eboos.common.entity.supplier.vo.CombinationProductVo;
import com.cloud.drore.eboos.common.entity.supplier.vo.TicketAllVo;
import com.cloud.drore.eboos.exception.BusinessException;
import com.cloud.drore.eboss.login.user.Anon;
import com.cloud.drore.eboss.supplier.entity.CombinationProduct;
import com.cloud.drore.eboss.supplier.entity.po.CombinationProductPo;
import com.cloud.drore.eboss.supplier.entity.vo.DictionaryTicketVo;
import com.cloud.drore.eboss.supplier.service.impl.CombinationProductServiceImpl;
import com.cloud.drore.eboss.supplier.service.impl.TicketServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.sql.ResultSet;

/**
 * 浙江卓锐科技股份有限公司 版权所有  Copyright 2018<br>
 *
 * @Description: <br>
 * @Project: eboos <br>
 * @CreateDate: Created in 2018/1/8 14:35 <br>
 * @Author: <a href="575842778@qq.com">郑永涛</a>
 */
@RestController
@RequestMapping("/combinationProduct")
@Api(value = "/组合产品接口", description = "组合产品接口-郑永涛")
public class CombinationProductController {

    @Resource
    CombinationProductServiceImpl combinationProductService;
    @Resource
    TicketServiceImpl ticketService;
    static final String THE_SHELVES = "THE_SHELVES";

    /**
     * @ClassName: CombinationProductController
     * @param resultSet
     * @Return: java.sql.ResultSet
     * @Decription:
     * @CreateDate: Created in 2018/1/8 14:37
     * @Author: <a href="575842778@qq.com">郑永涛</a>
     * @Modify:
     */
    public ResultSet get(ResultSet resultSet){
        return null;
    }

    @ApiOperation(value = "保存组合产品信息")
    @PostMapping(value = "/saveCombinationProduct")
    public ResultMessage<CombinationProduct> saveCombinationProduct(@RequestBody CombinationProductPo combinationProduct) throws BusinessException {
        return combinationProductService.saveCombinationProduct(combinationProduct.getCombinationProduct(),
                combinationProduct.getCombinationProductPrices(),combinationProduct.getCombinationProductStocks(),combinationProduct.getCombinationProductRelationList());
    }

    @ApiOperation(value = "更新组合产品信息")
    @PutMapping(value = "/updateCombinationProduct")
    public ResultMessage<CombinationProduct> updateCombinationProduct(@RequestBody CombinationProductPo combinationProduct) throws BusinessException {
        return combinationProductService.updateCombinationProduct(combinationProduct.getCombinationProduct(),
                combinationProduct.getCombinationProductPrices(),combinationProduct.getCombinationProductStocks());
    }

    @Anon
    @ApiOperation(value = "查询组合产品信息详情")
    @GetMapping(value = "/selectCombinationProductById/{id}")
    public ResultMessage<CombinationProductVo> selectCombinationProductById(@PathVariable("id") Long id) throws BusinessException {
        return new ResultMessage(combinationProductService.selectCombinationProductById(id));
    }

    @ApiOperation(value = "查询组合产品信息详情供应商")
    @GetMapping(value = "/selectCombinationProductByIdSupplier/{id}")
    public ResultMessage<CombinationProductVo> selectCombinationProductByIdSupplier(@PathVariable("id") Long id) throws BusinessException {
        return new ResultMessage(combinationProductService.selectCombinationProductByIdSupplier(id));
    }

    @ApiOperation(value = "分页查询组合产品信息")
    @PostMapping(value = "/findCombinationProductByParam")
    public ResultMessage findCombinationProductByParam(@RequestBody PagePo<CombinationProductQueryPo> pagePo) throws BusinessException {
        return ResultMessage.success(combinationProductService.findCombinationProductByParam(pagePo));
    }

    @Anon
    @ApiOperation(value = "分页查询组合产品信息分销商")
    @PostMapping(value = "/findCombinationProductByParamDealer")
    public ResultMessage findCombinationProductByParamDealer(@RequestBody PagePo<CombinationProductQueryPo> pagePo) throws BusinessException {
        return ResultMessage.success(combinationProductService.findCombinationProductByParamDealer(pagePo));
    }

    @ApiOperation(value = "分页查询组合产品信息供应商")
    @PostMapping(value = "/findCombinationProductByParamSupplier")
    public ResultMessage findCombinationProductByParamSupplier(@RequestBody PagePo<CombinationProductQueryPo> pagePo) throws BusinessException {
        return ResultMessage.success(combinationProductService.findCombinationProductByParamSupplier(pagePo));
    }

    @ApiOperation(value = "上下架、审核产品，更改产品状态")
    @GetMapping(value = "/updateStatus/{id}/{status}")
    public ResultMessage<Ticket> updateStatus(@PathVariable("id") Long id, @PathVariable("status") String status) throws BusinessException {
        return combinationProductService.updateStatus(id,status);
    }

    @ApiOperation(value = "组合产品中根据条件分页查询门票信息")
    @PostMapping(value = "/findTicketByParam")
    public ResultMessage<TicketAllVo> findTicketByParam(@RequestBody PagePo<TicketQueryPo> pagePo) throws BusinessException{
        return ResultMessage.success(combinationProductService.findTicketByParamWithoutExpired(pagePo));
    }

    @Anon
    @ApiOperation(value = "根据组合产品id查询子产品集合")
    @GetMapping(value = "/findProductByCombinationId/{combinationId}")
    public ResultMessage<TicketAllVo> findProductByCombinationId(@PathVariable("combinationId") Long combinationId) throws BusinessException{
        return ResultMessage.success(combinationProductService.findProductByCombinationId(combinationId));
    }

    @ApiOperation(value = "审核驳回")
    @GetMapping(value = "/reject/{id}/{status}/{rejectReason}")
    public ResultMessage<Ticket> rejectProduct(@PathVariable("id") Long id, @PathVariable("status") String status,@PathVariable("rejectReason") String rejectReason) throws BusinessException {
        return combinationProductService.rejectProduct(id,status,rejectReason);
    }

    @ApiOperation(value = "查询全部产品(首页接口)")
    @GetMapping(value = "/findAllProduct")
    public ResultMessage<ProductRelation> findAllProduct() throws BusinessException {
        return combinationProductService.findAllProduct();
    }

    @ApiOperation(value = "初始化获取组合产品列表字典信息")
    @GetMapping(value = "/init")
    public ResultMessage<DictionaryTicketVo> init() {
        return combinationProductService.init();
    }

}